class Shop < ActiveRecord::Base
	belongs_to :user
	
	named_scope :admin_search, lambda { |params|
    search_params = params.dup
    search_params[:shop_id] = "%#{params[:shop_id].strip if params[:shop_id]}%"
    search_params[:shop_title] = "%#{params[:shop_title].strip if params[:shop_title]}%"
    #search_params[:cat1_id] = "#{params[:cat1_id].strip unless params[:cat1_id].blank?}"
    #search_params[:cat2_id] = "#{params[:cat2_id].strip unless params[:cat2_id].blank?}"
    #search_params[:cat3_id] = "#{params[:cat3_id].strip unless params[:cat3_id].blank?}"
    conds = ["shops.id LIKE :shop_id",
      "shops.shop_title LIKE :shop_title"]
      #conds << "items.cat1_id = :cat1_id" unless params[:cat1_id].blank?
      #conds << "items.cat2_id = :cat2_id" unless params[:cat2_id].blank?
      #conds << "items.cat3_id = :cat3_id" unless params[:cat3_id].blank?
      conds << "shops.status <> 0"
      { :conditions => [conds.join(' and '), search_params] }
  }
end
